package com.qding.park.manager.service.core.biz;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.exceptions.ExceptionMessage;
import com.qding.park.common.core.exceptions.business.manager.service.ServiceCoreException;
import com.qding.park.common.utils.ListUtil;
import com.qding.park.manager.adapter.factory.AdapterParkProxyFactory;
import com.qding.park.manager.cache.ParkCacheInter;
import com.qding.park.manager.pojo.TbCar;
import com.qding.park.manager.pojo.TbParkspace;
import com.qding.park.manager.pojo.TbUserInfo;
import com.qding.park.manager.pojo.ap.ApUserCarInfo;
import com.qding.park.manager.pojo.enums.CardStatuEnum;
import com.qding.park.manager.pojo.enums.CardTypeEnum;
import com.qding.park.manager.pojo.enums.RecordStatusEnum;
import com.qding.park.manager.pojo.enums.UserTypeEnum;
import com.qding.park.manager.service.core.atomic.distributed.UserDBAtomic;
import com.qding.park.manager.service.core.mapper.TbCarMapper;
import com.qding.park.manager.service.core.mapper.TbParkspaceMapper;
import com.qding.park.manager.service.core.mapper.TbSupplycomanyMapper;
import com.qding.park.manager.service.core.mapper.TbUserInfoMapper;

/**
 * @ClassName CarBiz
 * @Description TODO(与车辆有关的业务)
 * @author Administrator
 * @Date 2016年8月25日 上午10:13:18
 * @version 1.0.0
 * 
 * 
 */
@Component("carBiz")
public class CarBiz {

	private static final Log _log = LogFactory.getLog(CarBiz.class);

	@Autowired
	private TbParkspaceMapper tbParkspaceMapper;

	@Autowired
	private TbUserInfoMapper tbUserInfoMapper;

	@Autowired
	private TbCarMapper tbCarMapper;

	@Autowired
	private TbSupplycomanyMapper tbSupplycomanyMapper;

	@Autowired
	private AdapterParkProxyFactory adapterParkProxyFactory;

	@Autowired
	private UserDBAtomic userDBAtomic;
	
	@Autowired
	private  ParkCacheInter  parkCacheInter;

	/**
	 * login(登录操作)
	 *
	 * @Title: structure_loginUser @Description: TODO @param @param tel
	 *         手机号 @param @param bjuserId 北京用户id @param @return 设定文件 @return
	 *         TbUserInfo 返回类型 @throws
	 */
	// public TbUserInfo structure_loginUser(String tel, String bjuserId, int
	// userType) throws BaseException {
	// _log.info("tel=" + tel + ",bjuserId=" + bjuserId + ",userType=" +
	// userType);
	//
	// if (StringUtils.isBlank(tel)) {
	// throw new
	// ServiceCoreException(ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_INVALID.getId(),
	// null,
	// ExceptionMessage.createExceptionMessage(
	// ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_INVALID.getDesc(),
	// "手机号不能为空",
	// " tel=" + tel + ",bjuserId=" + bjuserId));
	// }
	//
	// // TbUserInfo
	// // tbUserInfo=tbUserInfoMapper.queryUserByTel(Long.valueOf(tel));
	// if (StringUtils.isBlank(bjuserId)) {
	// // 单手机号
	// _log.info("目前暂不实现!!");
	//
	// } else {
	// // 有用户id及手机号
	// TbUserInfo tbUserInfo = new TbUserInfo();
	// tbUserInfo.setTel(Long.valueOf(tel));
	// tbUserInfo.setBjCode(bjuserId);
	// tbUserInfo.setUserType(userType);
	// if (userDBAtomic.saveUserAtomicTelNotExists(tbUserInfo)) {
	// return tbUserInfo;
	// }
	// // if(tbUserInfo==null){
	// // tbUserInfo=new TbUserInfo();
	// // tbUserInfo.setTel(Long.valueOf(tel));
	// // tbUserInfo.setBjCode(bjuserId);
	// // tbUserInfo.setUserType(userType);
	// // tbUserInfoMapper.save(tbUserInfo);
	// // return tbUserInfo;
	// // }
	// TbUserInfo u = tbUserInfoMapper.queryUserByTel(Long.valueOf(tel));
	// if (StringUtils.isBlank(u.getBjCode())) {
	// // bjuserid 为空
	// // int num=tbUserInfoMapper.updateBjuseridByPhone(bjuserId,
	// // Long.valueOf(tel));
	// u.setUserType(userType);
	// u.setBjCode(bjuserId);
	// int num = tbUserInfoMapper.update(u);
	// return u;
	// }
	//
	// if (bjuserId.equals(u.getBjCode())) {
	// // 两个用户id 是一样的
	// return u;
	// } else {
	// throw new
	// ServiceCoreException(ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_INVALID.getId(),
	// null,
	// ExceptionMessage.createExceptionMessage(
	// ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_INVALID.getDesc(),
	// "请联络物业管理处更新登记车辆时预留的手机号", " tel=" + tel + ",bjuserId=" + bjuserId));
	// }
	//
	// }
	//
	// return null;
	// }

	// /**
	// * @throws BaseException login(登录操作)
	// *
	// * @Title: structure_loginUser @Description: TODO @param @param tel
	// * 手机号 @param @return 设定文件 @return TbUserInfo 返回类型 @throws
	// */
	// public TbUserInfo structure_loginUser(String tel, int userType) throws
	// BaseException {
	// return structure_loginUser(tel, null, userType);
	// }

	/**
	 * @Description (查询车辆列表)
	 * @param bjUserId
	 *            北京用户id
	 * @param phone
	 *            手机号
	 * @return
	 */
	public List<TbCar> queryMyCarsByBjcode(String bjUserId) {

		List<TbCar> carlist = tbCarMapper.queryMyCarsByBjcode(bjUserId);
		return carlist;

	}

	/**
	 * mycars_wx(微信用户名下车辆列表) TODO(这里描述这个方法适用条件 – 可选) TODO(这里描述这个方法的执行流程 – 可选)
	 * TODO(这里描述这个方法的使用方法 – 可选) TODO(这里描述这个方法的注意事项 – 可选)
	 *
	 * @Title: mycars_wx @Description: TODO @param @param phone @param @param
	 *         userId @param @return 设定文件 @return List<TbCar> 返回类型 @throws
	 */
	public List<TbCar> mycars_wx(long phone, String userId) {
		List<TbCar> carlist = tbCarMapper.mycars_wx(userId);
		return carlist;
	}

	public TbUserInfo getUserWX(long phone, String bjuserId) {
		// TbUserInfo
		// TbUserInfo
		// userinfo=tbUserInfoMapper.queryUseByBjuseridType(bjuserId,UserTypeEnum.WX_VISITOR_USER.getType());

		TbUserInfo userinfo = tbUserInfoMapper.queryUserByBjUserId(bjuserId);
		if (userinfo == null) {
			// 增加用户
			userinfo = new TbUserInfo();
			userinfo.setTel(phone);
			userinfo.setUserType(UserTypeEnum.WX_VISITOR_USER.getType());
			userinfo.setCreate_date(new Date());
			userinfo.setStatus(RecordStatusEnum.EFFICIENCY.getStatus());
			userinfo.setBjCode(bjuserId);
			int num = tbUserInfoMapper.save(userinfo);
		}
		return userinfo;
	}

	// public TbUserInfo getUserWX(long phone,String bjuserId){
	// TbUserInfo
	// userinfo=tbUserInfoMapper.queryUseByBjuseridType(bjuserId,UserTypeEnum.WX_VISITOR_USER.getType());
	// if(userinfo==null){
	// //增加用户
	// userinfo=new TbUserInfo();
	// userinfo.setTel(phone);
	// userinfo.setUserType(UserTypeEnum.WX_VISITOR_USER.getType());
	// userinfo.setCreate_date(new Date());
	// userinfo.setStatus(RecordStatusEnum.EFFICIENCY.getStatus());
	// userinfo.setBjCode(bjuserId);
	// int num=tbUserInfoMapper.save(userinfo);
	// if(num==0){
	// userinfo=tbUserInfoMapper.queryUseByBjuseridType(bjuserId,UserTypeEnum.WX_VISITOR_USER.getType());
	// }else{
	// }
	// }else{
	//
	// if(phone!=userinfo.getTel()){
	// tbUserInfoMapper.updataTel(phone,bjuserId,UserTypeEnum.WX_VISITOR_USER.getType());
	// }
	// }
	//
	// return userinfo;
	// }

	// @Transactional(rollbackFor = Throwable.class)
	// public TbUserInfo getUserAPP(String bjuserId) {
	// // TbUserInfo userinfo =
	// // tbUserInfoMapper.queryUseByBjuseridType(bjuserId,
	// // UserTypeEnum.REGISTER_USER.getType());
	// TbUserInfo userinfo = tbUserInfoMapper.queryUserByBjUserId(bjuserId);
	// if (userinfo == null) {
	// // 增加用户
	// userinfo = new TbUserInfo();
	// userinfo.setUserType(UserTypeEnum.REGISTER_USER.getType());
	// userinfo.setCreate_date(new Date());
	// userinfo.setStatus(RecordStatusEnum.EFFICIENCY.getStatus());
	// userinfo.setBjCode(bjuserId);
	// int num = tbUserInfoMapper.save(userinfo);
	// } else {
	// }
	//
	// return userinfo;
	// }

	@Transactional(rollbackFor = Throwable.class)
	public TbUserInfo getUserAPP(String bjuserId) {
		// TbUserInfo userinfo =
		// tbUserInfoMapper.queryUseByBjuseridType(bjuserId,
		// UserTypeEnum.REGISTER_USER.getType());
		TbUserInfo userinfo = tbUserInfoMapper.queryUserByBjUserId(bjuserId);
		if (userinfo == null) {
			// 增加用户
			userinfo = new TbUserInfo();
			userinfo.setUserType(UserTypeEnum.REGISTER_USER.getType());
			userinfo.setCreate_date(new Date());
			userinfo.setStatus(RecordStatusEnum.EFFICIENCY.getStatus());
			userinfo.setBjCode(bjuserId);
			int num = tbUserInfoMapper.save(userinfo);
		} else {
		}

		return userinfo;
	}

	/**
	 * addCar_wx(微信用户添加车辆)
	 *
	 * @Title: addCar_wx @Description: TODO @param @param phone @param @param
	 *         carNum 设定文件 @return void 返回类型 @throws
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void addCar_wx(long phone, String bjuserId, String carNum) throws BaseException {

		TbUserInfo tbUserInfo = getUserWX(phone, bjuserId);
		int userId = tbUserInfo.getId();
		List<TbCar> tcars = tbCarMapper.queryByBjuserCarnum(bjuserId, carNum);
		if (!ListUtil.isEmpty(tcars)) {
			throw new ServiceCoreException(ServiceCoreException.TypeEnum.EXCEPTION_DATA_DIFF.getId(), null,
					ExceptionMessage.createExceptionMessage(ServiceCoreException.TypeEnum.EXCEPTION_DATA_DIFF.getDesc(),
							"此车辆已经绑定", " 车牌=" + carNum));
		}
		TbCar car = new TbCar();
		car.setCarNum(carNum);
		car.setUserID(userId);
		car.setCardType(CardTypeEnum.TEMP_TYPE.getType());
		int temp = tbCarMapper.insetNoExists(car);
	}

	@Transactional(rollbackFor = Throwable.class)
	public void deleteCar_wx(long phone, String bjuserId, String carNum) {
		TbUserInfo tbUserInfo = getUserWX(phone, bjuserId);
		int userId = tbUserInfo.getId();
		TbCar car = new TbCar();
		car.setCarNum(carNum);
		car.setUserID(userId);
		// int temp=tbCarMapper.insetNoExists(car);
		tbCarMapper.delete_wx(car);

	}

	// @CacheEvict
	// @Caching
	public List<TbCar> queryCarOfParkByCarNum(String carNum) {
		List<TbCar> carlist = tbCarMapper.queryCarOfParkByCarNum(carNum);
		return carlist;

	}

	public List<TbCar> queryCarInfo(String bjuserid, String carNum) {
		List<TbCar> carlist = tbCarMapper.queryByBjuserCarnum(bjuserid, carNum);
		return carlist;
	}

	/**
	 * userCarInfoSync(用户、用户登记车牌信息同步) TODO(这里描述这个方法适用条件 – 可选) TODO(这里描述这个方法的执行流程
	 * – 可选) TODO(这里描述这个方法的使用方法 – 可选) TODO(这里描述这个方法的注意事项 – 可选)
	 *
	 * @Title: userCarInfoSync @Description: TODO @param @throws
	 *         AdapterProxyCreateFail @param @throws
	 *         AdapterException @param @throws NetWorkException 设定文件 @return
	 *         void 返回类型 @throws
	 */
//	public void userCarInfoSync() throws AdapterProxyCreateFail, AdapterException, NetWorkException {
//
//		// 查询所有的车场列表
//		List<TbParkspace> parkSpaceList = tbParkspaceMapper.listAll();
//		if (ListUtil.isEmpty(parkSpaceList)) {
//			_log.info("车场列表为空，同步任务已完成");
//			return;
//		}
//
//		_log.info("同步车场的用户数据 size=" + parkSpaceList.size());
//		for (TbParkspace park : parkSpaceList) {
//
//			String parkCode = park.getParkCode();
//			int supplierId = park.getSupplierId();
//			AdapterProxy adapterProxy = adapterParkProxyFactory.createAdapterParkProxyBySupplierId(supplierId);
//
//			List<ApUserCarInfo> apusercarList = adapterProxy.getCarAdapter().allUserCar(parkCode);
//
//			syncUser(apusercarList);
//			syncUsercaReleation(apusercarList, park);
//		}
//	}
	
//	public void userCarInfoSync() throws AdapterProxyCreateFail, AdapterException, NetWorkException {
//
//		// 查询所有的车场列表
//		List<TbParkspace> parkSpaceList = tbParkspaceMapper.listAll();
//		if (ListUtil.isEmpty(parkSpaceList)) {
//			_log.info("车场列表为空，同步任务已完成");
//			return;
//		}
//
//		_log.info("同步车场的用户数据 size=" + parkSpaceList.size());
//		for (TbParkspace park : parkSpaceList) {
//
////			String parkCode = park.getParkCode();
////			int supplierId = park.getSupplierId();
////			AdapterProxy adapterProxy = adapterParkProxyFactory.createAdapterParkProxyBySupplierId(supplierId);
////
////			List<ApUserCarInfo> apusercarList = adapterProxy.getCarAdapter().allUserCar(parkCode);
////
////			syncUser(apusercarList);
////			syncUsercaReleation(apusercarList, park);
//		}
//	}

//	public void userCarInfoSync(int parkId) throws BaseException {
//
//		TbParkspace tbParkspace=parkCacheInter.queryParkSpace(parkId);
//		if (tbParkspace == null) {
//			_log.info("车场列表为空，同步任务已完成");
//			throw new ServiceCoreException(ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_FIND.getId(), null,
//					ExceptionMessage.createExceptionMessage(
//							ServiceCoreException.TypeEnum.EXCEPTION_NO_DATA_FIND.getDesc(), "无此车场", " 车牌=" + parkId));
//		}
//
//		_log.info("同步车场的用户数据 size=" + 1);
//
//		String parkCode = tbParkspace.getParkCode();
//		int supplierId = tbParkspace.getSupplierId();
//		AdapterProxy adapterProxy = adapterParkProxyFactory.createAdapterParkProxyBySupplierId(supplierId);
//
//		List<ApUserCarInfo> apusercarList = adapterProxy.getCarAdapter().allUserCar(parkCode);
//
//		syncUser(apusercarList);
//		syncUsercaReleation(apusercarList, tbParkspace);
//	}

	private long  tel2Long(String str){
	    
	    long tel=-1L;
	    
	    try{
	        tel=Long.valueOf(str);
	    }catch(Exception e){
	        _log.error(e, e);
	    }
	    return tel;
	}
	
	/**
	 * syncUser(同步用户信息) TODO(这里描述这个方法适用条件 – 可选) TODO(这里描述这个方法的执行流程 – 可选)
	 * TODO(这里描述这个方法的使用方法 – 可选) TODO(这里描述这个方法的注意事项 – 可选) @Title:
	 * syncUser @Description: TODO @param @param apusercarList 设定文件 @return void
	 * 返回类型 @throws
	 */
//	@Transactional(rollbackFor = Throwable.class)
	private void syncUser(List<ApUserCarInfo> apusercarList) {
		List<TbUserInfo> tbuserList = new ArrayList<TbUserInfo>();

		Set<String> tagSet = new HashSet<String>();
		if (!ListUtil.isEmpty(apusercarList)) {
			for (ApUserCarInfo ap : apusercarList) {

				String tels = ap.getContact_Tel1();
				String name = ap.getMember_Name();
				String carNum = ap.getCarNumber();
				String homeAddr=ap.getHome_Address();
				String[] telArray = tels.split(",");
				for (String t : telArray) {
					if (StringUtils.isBlank(t) || tagSet.contains(t)) {
						continue;
					}
					TbUserInfo u = new TbUserInfo();
//					u.setTel(Long.valueOf(t.trim()));
					u.setTel(tel2Long(t));
					tbuserList.add(u);
					u.setName(name);
					u.setHomeAddr(homeAddr);

					tagSet.add(t);
				}
			}

			for (TbUserInfo userInfo : tbuserList) {
				// TbUserInfo u =
				// tbUserInfoMapper.queryUserByTel(userInfo.getTel());
				userInfo.setUserType(UserTypeEnum.REGISTER_USER.getType());
//				if(userInfo.getName().equals("雷阳")){
//					System.out.println("dd");
//				}
				int num = tbUserInfoMapper.update(userInfo);

//				if (num == 0) {
					// userDBAtomic.saveUserAtomicTelNotExists(userInfo);
					userInfo.setUserType(UserTypeEnum.REGISTER_USER.getType());
					userDBAtomic.register_loginUser(userInfo);
//				}
				// if (u == null) {
				// tbUserInfoMapper.save(userInfo);
				//// tbUserInfoMapper.insertnotExistis(userInfo);
				// }else{
				// u.setUserType(UserTypeEnum.REGISTER_USER.getType());
				// tbUserInfoMapper.update(u);
				// }

			}
			// tbUserInfoMapper.batchInsert(tbuserList);
		}

	}

	/**
	 * syncUsercaReleation(同步用户登记车牌信息) TODO(这里描述这个方法适用条件 – 可选)
	 * TODO(这里描述这个方法的执行流程 – 可选) TODO(这里描述这个方法的使用方法 – 可选) TODO(这里描述这个方法的注意事项 –
	 * 可选)
	 *
	 * @Title: syncUsercaReleation @Description: TODO @param @param
	 *         apusercarList 设定文件 @return void 返回类型 @throws
	 */
//	@Transactional(rollbackFor = Exception.class)
	private void syncUsercaReleation(List<ApUserCarInfo> apusercarList, TbParkspace park) {
		int parkId = park.getId();
		int supplierId = park.getSupplierId();
		String parkName = park.getName();
		List<TbCar> tbusercarList = new ArrayList<TbCar>();
		List<TbCar> tbcarhas = tbCarMapper.listByParkid(parkId);
		Set<String> car_carnum_userid = new HashSet<String>();
		Set<String> car_carnum_userid_new = new HashSet<String>();
		for (ApUserCarInfo ap : apusercarList) {
			String tels = ap.getContact_Tel1();
			String[] telArray = tels.split(",");
			for (String t : telArray) {
				if (StringUtils.isBlank(t)) {
					continue;
				}
				TbUserInfo tbuserinfo = tbUserInfoMapper.queryUserByTel(tel2Long(t));
				if(tbuserinfo==null){
					continue;
				}
				int userid = tbuserinfo.getId();
				String carNum = ap.getCarNumber();
				int cardType = ap.getCardType();
				int cardState = ap.getCardState();
				int carType=ap.getCarType();
				int monthFee=ap.getMonthFee();
				String operator=ap.getRequireguy();//操作员
				String carSpace=ap.getCarpos();//车位
				Date issueTime=ap.getRequiretime();//发行时间
				String memeberName=ap.getMember_Name();
				Date expireDate = ap.getExpireDate();
				String cardName=ap.getCardDescript();

				TbCar car = new TbCar();
				car.setParkID(parkId);
				car.setSupplierId(supplierId);
				car.setParkName(parkName);
				car.setUserID(userid);
				car.setCarNum(carNum);
				car.setStatus(cardState);
				car.setCardType(cardType);
				car.setCardExpiration(expireDate);
				car.setCarType(carType);
				car.setMonthFee(monthFee);
				car.setMemberName(memeberName);
				car.setCarSpace(carSpace);
				car.setIssueTime(issueTime);
				car.setOperator(operator);
				car.setCardName(cardName);
				tbusercarList.add(car);
			}

		}

		List<TbCar> inserts = new ArrayList<TbCar>();
		List<TbCar> updates = new ArrayList<TbCar>();
		List<TbCar> dels = new ArrayList<TbCar>();

		for (TbCar car : tbcarhas) {
			car_carnum_userid.add(parkId + ":" + car.getCarNum() + ":" + car.getUserID());
		}

		for (TbCar car : tbusercarList) {
			car_carnum_userid_new.add(parkId + ":" + car.getCarNum() + ":" + car.getUserID());
		}

		for (TbCar car : tbusercarList) {
			String tag = park.getId() + ":" + car.getCarNum() + ":" + car.getUserID();
			if (car_carnum_userid.contains(tag)) {
				updates.add(car);
			} else {
				// car.setId(tbCarMapper.getNextValue());
				inserts.add(car);
			}
		}

		for (TbCar car : tbcarhas) {
			String tag = park.getId() + ":" + car.getCarNum() + ":" + car.getUserID();
			if (!car_carnum_userid_new.contains(tag)) {
				car.setStatus(CardStatuEnum.DELETED_STATUS.getStatus());
				dels.add(car);
			}
		}

		// tbCarMapper.batchUpdate(tbusercarList);

		if (!ListUtil.isEmpty(updates)) {
			tbCarMapper.batchUpdate(updates);
			// for(TbCar car:updates){
			// tbCarMapper.updateExists(car);
			// }
		}
		if (!ListUtil.isEmpty(inserts)) {
			// tbCarMapper.batchInsert(inserts);
			for (TbCar car : inserts) {
				tbCarMapper.insetNoExists(car);
			}

		}
		if (!ListUtil.isEmpty(dels)) {
			tbCarMapper.batchUpdate(dels);
		}
		
		tbusercarList.clear();
		tbusercarList=null;
		inserts.clear();
		inserts=null;
		updates.clear();
		updates=null;
		dels.clear();
		dels=null;
		
	}

	// private void syncList(List list, TbParkspace park) {
	// try {
	// if (ListUtil.isEmpty(list)) {
	// return;
	// }
	//
	// List<ApUserCarInfo> userList = list;
	// List<TbUserInfo> tbUserList = new ArrayList<TbUserInfo>();
	//
	// Map<String, TbUserInfo> apUserTempMap = new HashMap<String,
	// TbUserInfo>();
	// List<TbUserInfo> userTempList = new ArrayList<TbUserInfo>();
	// List<TbCar> carTempList = new ArrayList<TbCar>();
	// for (ApUserCarInfo user : userList) {
	// if (StringUtils.isBlank(user.getContact_Tel1())) {
	// continue;
	// }
	// String[] tels = user.getContact_Tel1().split(",");
	//
	// for (String tel : tels) {
	// ApUserCarInfo tempuser = user.clone();
	// tempuser.setContact_Tel1(tel);
	// if (apUserTempMap.containsKey(tel)) {
	// String carstr = apUserTempMap.get(tel).getCarNum();
	// apUserTempMap.get(tel).setCarNum(
	// StringUtils.isBlank(carstr) ? user.getCarNumber() : carstr + "," +
	// user.getCarNumber());
	// } else {
	// TbUserInfo tbUserInfo = new TbUserInfo();
	// tbUserInfo.setCarNum(user.getCarNumber());
	// tbUserInfo.setTel(Long.valueOf(tel));
	// apUserTempMap.put(tel, tbUserInfo);
	// userTempList.add(tbUserInfo);
	// }
	//
	// TbCar car = new TbCar();
	// car.setParkID(park.getId());
	// car.setParkName(park.getParkCode());
	// car.setCarNum(user.getCarNumber());
	// car.setCardExpiration(user.getExpireDate());
	// car.setTel(tel);
	// car.setSupplierId(park.getSupplierId());
	// carTempList.add(car);
	// }
	// }
	//
	// // 批量更新用户表
	// tbUserInfoMapper.batchUpdateByid(userTempList);
	//
	// // 插入新增用户
	// for (TbUserInfo u : userTempList) {
	// if (tbUserInfoMapper.queryUserByTel(u.getTel()) == null) {
	// tbUserInfoMapper.save(u);
	// }
	// }
	//
	// /******** 更新车辆信息 *******************************/
	// for (TbCar car : carTempList) {
	// TbUserInfo tbUserinfo =
	// tbUserInfoMapper.queryUserByTel(Long.valueOf(car.getTel()));
	// car.setUserID(tbUserinfo.getId());
	// }
	//
	// List<TbCar> tbCars = tbCarMapper.listByParkid(park.getId());
	// Set<String> car_carnum_userid = new HashSet<String>();
	// for (TbCar car : tbCars) {
	// car_carnum_userid.add(park.getId() + ":" + car.getCarNum() + ":" +
	// car.getUserID());
	// }
	//
	// List<TbCar> inserts = new ArrayList<TbCar>();
	// List<TbCar> updates = new ArrayList<TbCar>();
	// for (TbCar car : carTempList) {
	// String tag = park.getId() + ":" + car.getCarNum() + ":" +
	// car.getUserID();
	// if (car_carnum_userid.contains(tag)) {
	// updates.add(car);
	// } else {
	// car.setId(tbCarMapper.getNextValue());
	// inserts.add(car);
	// }
	// }
	//
	// if (!ListUtil.isEmpty(updates)) {
	// tbCarMapper.batchUpdate(updates);
	// }
	// if (!ListUtil.isEmpty(inserts)) {
	// tbCarMapper.batchInsert(inserts);
	// }
	//
	// } catch (Exception e) {
	// throw new RuntimeException(e);
	// }
	// }

}
